package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.dto.ModifyStatusDto;
import com.itheima.dto.OrdersPageDto;
import com.itheima.pojo.Orders;
import com.itheima.service.OrdersService;
import com.itheima.vo.OrdersDetailVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("order")
@Slf4j
public class OrderController {

    @Resource
    private OrdersService ordersService;


    /**
     * 订单列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("userPage")
    public R getUserPage(@RequestParam(value = "page" ,defaultValue = "1")Integer page,
                         @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){

        Page<OrdersDetailVo> pageList = ordersService.getDetail(page, pageSize);

        return R.success(pageList);
    }

    /**
     * 订单提交
     * @param orders
     * @return
     */
    @PostMapping("submit")
    public R<String> submit(@RequestBody Orders orders){

        Boolean res = ordersService.submitOrders(orders);

        return res?R.success("提交成功"):R.error("提交失败");

    }

}

